package view.plugin
{
	//游戏中的气泡聊天
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.text.TextFormat;
	
	import global.Resource;
	
	import libs.tweener.Tweener;
	
	import util.RichTextArea;
	
	import view.plugin.ChatFace;
	
	public class GameChat extends Sprite
	{
		private var richTextArea:RichTextArea;
		private var obj1:Object;
		private var obj2:Object;
		public function GameChat(bg:DisplayObject,tpos:Point=null)
		{
			super();
			var txtFormat:TextFormat = new TextFormat("Courier New", 13, 0x0, false, false, false);	
			txtFormat.color = 0xFFFFFFFF;
//			txtFormat.align = "right";
			richTextArea = new RichTextArea(bg.width-30, bg.height);
			richTextArea.textField.selectable = false;
			richTextArea.defaultTextFormat = txtFormat;
			richTextArea.textField.wordWrap=true;
			richTextArea.textField.multiline=true;
			richTextArea.configXML = ChatFace.faceXML;
			if(!tpos)
			{
				richTextArea.x = 5;
				richTextArea.y = 8;
			}
			else
			{
				richTextArea.x = tpos.x;
				richTextArea.y = tpos.y;
			}
			addChild(bg);
			addChild(richTextArea);
			
			obj1 = {alpha:1, time:1.0};
			obj2 = {time:4.0, onComplete:onShowComplete};
		}
		public function appendRichText(text:String):void
		{
			richTextArea.clear();
			richTextArea.insertRichText(text);
			
			this.visible  = true;
			this.alpha = 0;
			Tweener.removeTweens(this, obj1);
			Tweener.removeTweens(this, obj2);
			Tweener.addTween(this, obj1);
			Tweener.addTween(this, obj2);
		}
		private function onShowComplete():void
		{
			this.visible  = false;
		}
		public function get textArea():RichTextArea
		{
			return richTextArea;
		}
		public function set align(a:String):void
		{
			var txtFormat:TextFormat =  richTextArea.defaultTextFormat;
			txtFormat.align = a;
			richTextArea.defaultTextFormat = txtFormat;
		}
	}
}